//
// Created by xyb on 16/1/9.
//
#include <jni.h>
#include "com_uhylab_uhuvinetest_qrcamera_activity_CreateBitmapThread.h"
#include "Color.h"
#include "Algorithm.h"
#include <android/log.h>

#define LOG_TAG "FaceDetection/DetectionBasedTracker"
#define LOGE(...) ((void)__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__))

JNIEXPORT jfloatArray JNICALL Java_com_uhylab_uhuvinetest_qrcamera_activity_CreateBitmapThread_GetColor
        (JNIEnv *env, jobject jobject1, jbyteArray array, jint jint1, jint jint2, jint jint3) {
    unsigned char *data = (unsigned char *) env->GetByteArrayElements(array, 0);
    float H = 0;
    float S = 0;
    float V = 0;
    jfieldID arrColorId;
    jclass cls = env->GetObjectClass(jobject1);
    arrColorId = env->GetFieldID(cls, "types", "[I");
    jfloat jfloat1[33];
    jint nArr[11];
    jintArray jnArray = env->NewIntArray(11);

    jfloatArray array1 = env->NewFloatArray(33);
    for (int i = 0; i < 11; i++) {
        RGB_HSV(data[i * 3 + 0], data[i * 3 + 1], data[i * 3 + 2], H, S, V);
        nArr[i] = Algorithm(i, data[i * 3 + 0], data[i * 3 + 1], data[i * 3 + 2]);
        jfloat1[i * 3 + 0] = H;
        jfloat1[i * 3 + 1] = S;
        jfloat1[i * 3 + 2] = V;
    }

    env->SetIntArrayRegion(jnArray, 0, 11, nArr);
    env->SetObjectField(jobject1, arrColorId, jnArray);

    env->SetFloatArrayRegion(array1, 0, 33, jfloat1);
    return array1;
};

